package org.nextcore.ai.controller;

import org.nextcore.ai.config.AIConfig;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.Objects;

@RestController
public class AIController {

    private final ChatClient chatClient;

    AIController(ChatClient chatClient){
        this.chatClient = chatClient;
    }

    @GetMapping("/ai/simple")
    public Map<String, String> completion(@RequestParam(
            value = "message",
            defaultValue = "Tell me a joke"
    ) String message){
        return Map.of("completion", Objects.requireNonNull(this.chatClient.prompt().user(message).call().content()));
    }
}
